import { IRoute } from "@/redux/modules/tag/tag.type";

export interface MetaProps {
    isAuth?: boolean;
    title: string;
    key?: string;
}

export interface RouteObject {
    children?: RouteObject[];
    element?: React.ReactNode;
    path?: string;
    meta?: MetaProps
}

export const matchRoute = (path: string, routes: RouteObject[] = []): any => {
    let result = {};
    for (let item of routes) {
        if (item.path == path) {
            return item
        };
        if (item.children?.length) {
            const res = matchRoute(path, item.children);
            if (Object.keys(res).length) {
                result = res;
            }
        }
    }
    return result
}